export default {
    isLoading: 0,
    loading: function(text = '加载中...') {
        if(this.isLoading <= 0) {
            uni.showLoading({
                mask: true,
                title: text
            })
        }
        this.isLoading++;
    },
    loaded: function() {
        this.isLoading--;
        if(this.isLoading <= 0) {
            uni.hideLoading()
        }
    },
    toast: function(title, duration = 1500, icon = 'none') {
        return new Promise(resolve => {
            uni.showToast({
                icon,
                mask: true,
                title,
                duration,
                success(res) {
                    setTimeout(() => {
                        resolve(res)
                    }, duration)
                }
            })
        })
    },
    confirm: function(title, content, confirmText = '确定', cancelText = '取消') {
        return new Promise((resolve, reject) => {
            uni.showModal({
                title,
                content,
                confirmText,
                cancelText,
                success(res) {
                    if(res.confirm) {
                        resolve(1)
                    } else {
                        resolve(0)
                    }
                },
                fail() {
                    reject()
                }
            })
        })
    }
}